/*
 * ExtensionLoader.java
 *
 * Created on 23. Februar 2007, 16:27
 *
 * Copyright (c) 2007 Daniel Gronau
 *
 * This file is part of KanjiTori.
 *
 * KanjiTori is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * KanjiTori is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

package kanjitori.abstraction;

import kanjitori.abstraction.AbstractFactory;
import kanjitori.abstraction.Factory;

/**
 *
 * @param Content 
 * @author Pirx
 */
public class ExtensionLoader<Content> extends AbstractFactoryImpl<Content> implements  AbstractFactory<Content>, Factory<Content> {

    /**
     * Implements the Factroy interface.
     * @param fileName 
     * @return the Map, or null (if no MapLoader was found for this extension)
     */
    public Content get(String fileName) {
        int index = fileName.lastIndexOf('.');
        if (index != -1) {
            String ext = fileName.substring(index + 1).toLowerCase();
            Factory<Content> loader = getFactory(ext);
            if (loader != null) {
                return loader.get(fileName);
            }
        }
        return null;
    }
    
}
